<?php
// 用户模型
class UserModel extends CommonModel {
	public $_validate	=	array(
		array('account','/^[a-z]\w{3,}$/i','帐号格式错误'),
		array('password','require','密码必须'),
		array('nickname','require','昵称必须'),
		array('repassword','require','确认密码必须'),
		array('repassword','password','确认密码不一致',self::EXISTS_VAILIDATE,'confirm'),
		array('account','','帐号已经存在',self::EXISTS_VAILIDATE,'unique',self::MODEL_INSERT),
		);

	public $_auto		=	array(
		array('password','pwdHash',self::MODEL_BOTH,'callback'),
		array('create_time','time',self::MODEL_INSERT,'function'),
		array('update_time','time',self::MODEL_UPDATE,'function'),
		);

	protected function pwdHash() {
		if(isset($_POST['password'])) {
			return pwdHash($_POST['password']);
		}else{
			return false;
		}
	}
	public function getlist($fields,$page,$limit) {
		$limit  =  isset($limit) ? intval($limit) : 25;
		$page  =  is_numeric($page) ? intval($page) : 0;
		if($fields) $this->field($fields);else $this->field('*');
		foreach($this->limit($page.','.$limit)->select() as $value){
			$value['last_login_time'] = date('r',$value['create_time']);
			$value['create_time'] = date('r',$value['create_time']);
			$list[] = $value;
		}
		unset($value);
		$array	= array(
			'count' =>$this->count('*'),
			'list' =>$list
		);
		return json_encode($array);
	}
}
?>